package com.codeduck.account.dubbo;

import com.codeduck.account.domain.AccountDO;
import com.codeduck.account.service.IAccountService;
import com.codeduck.common.dubbo.IAccountDubboService;
import com.codeduck.common.response.AccountResponse;
import com.codeduck.common.response.ServiceResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2022-08-19
 */
@Service
@Slf4j
public class AccountDubboService implements IAccountDubboService {

    @Resource
    private IAccountService accountService;

    @Override
    public ServiceResponse<AccountResponse> decreaseAccount(String userId, BigDecimal money) {
        log.info("账户费用扣除请求 = [userId:{}, money:{}]", userId, money);
        AccountDO accountDO = accountService.decreaseAccount(userId, money);
        AccountResponse response = AccountResponse
                .builder()
                .userId(accountDO.getUserId())
                .money(accountDO.getMoney())
                .build();
        return ServiceResponse.asOk(response);
    }
}
